package com.smart.utl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

/**
 * 
 * 
 * @author springside
 * 
 */
@SuppressWarnings("serial")
public class PageListUtil<E> extends ArrayList<E> implements Serializable {
	protected static int getStartOfPage(int pageNo) {
		return getStartOfPage(pageNo, 20);
	}
	public static int getStartOfPage(int pageNo, int pageSize) {
		return (pageNo - 1) * pageSize;
	}
	private int pageCount = 20;

	private int position = 0;

	private long totalCount;

	public PageListUtil() {
		super();
	}

	public PageListUtil(Collection<? extends E> c) {
		super(c);

		// TODO Auto-generated constructor stub
	}

	public PageListUtil(int initialCapacity) {
		super(initialCapacity);
		// TODO Auto-generated constructor stub
	}

	public PageListUtil(long totalSize, int position, int pageCount, Collection<? extends E> data) {
		super(data);
		this.totalCount = totalSize;
		this.pageCount = pageCount;
		this.position = position;

	}

	public int getCurrentPage() {
		return position / pageCount + 1;
	}

	public int getPageSize() {
		return pageCount;
	}

	public long getTotalCount() {
		return this.totalCount;
	}

	public int getTotalPage() {
		if (totalCount % pageCount == 0)
			return (int) (totalCount / pageCount);
		else
			return (int) (totalCount / pageCount + 1);
	}

	public boolean hasNextPage() {
		return this.getCurrentPage() < this.getTotalPage() - 1;
	}

	public boolean hasPreviousPage() {
		return this.getCurrentPage() > 1;
	}
}